home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Tools / Text-Viewer / MSWordView / notes / decompress / ex2.c next >
Encoding:
C/C++ Source or Header  |  1999-11-06  |  945 b   |  45 lines

  1. #include <assert.h>
  2. #include <stdio.h>
  3. #include "zlib.h"
  4. #include "zutil.h"
  5.  
  6. int main(int argc, char *argv[])
  7. {
  8.   char *compr;
  9.   char uncompr[99999];
  10.   FILE* fp;
  11.   int err;
  12.   uLong uncomprLen, comprLen;
  13.  
  14.   /* We want status messages */
  15.   z_verbose = 1;
  16.   
  17.   fp = fopen("graphic.wmf.lzzed", "r");
  18.   assert(fp);
  19.  
  20.   /* Figure out the size of the file in a boring way*/
  21.   assert(fseek(fp, 0, SEEK_END) == 0);
  22.   comprLen = ftell(fp);
  23.   assert(fseek(fp, 0, SEEK_SET) == 0);
  24.  
  25.   /* Read in the file contents */
  26.   assert(compr = malloc(comprLen));
  27.   assert(fread(compr, comprLen, 1, fp));
  28.   fclose(fp);
  29.  
  30.   uncomprLen = sizeof(uncompr);    /* This was the trick :( */
  31.   err = uncompress(uncompr, &uncomprLen, compr, comprLen);
  32.  
  33.   if (err != Z_OK) {
  34.     fprintf(stderr, "error: %d\n", err); 
  35.     exit(1); 
  36.   } 
  37.  
  38.   /* Write out uncompressed data */
  39.   assert(fp = fopen("t.t", "w"));
  40.   assert(fwrite(uncompr, uncomprLen, 1, fp));
  41.   fclose(fp);
  42.   
  43.   return 0;
  44. }
  45.